layui.use(['layer', 'form', 'table', 'admin', 'ax', 'laydate'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var laydate = layui.laydate;
    var admin = layui.admin;

    /**
     * 系统管理--角色管理
     */
    var AmountRecord = {
        tableId: "amountRecordTable",    //表格id
        condition: {
        	nickname: ""
        }
    };

    //渲染时间选择框
    laydate.render({
        elem: '#timeLimit',
        range: true,
        max: Feng.currentDate()
    });
    /**
     * 初始化表格的列
     */
    AmountRecord.initColumn = function () {
        return [[
        	{type: 'checkbox'},
        	{field: 'recordId',align:'center', title: '流水编号'},
        	{field: 'phone',sort: true, title: '电话'},
        	{field: 'businessName', sort: true, title: '备注'},
        	{field: 'amount',sort: true, title: '流水金额'},
            {field: 'createTime',sort: true, title: '付款时间'},
            {field: 'successBalance',sort: true, title: '钱包剩余金额'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    AmountRecord.search = function () {
        var queryData = {};
        queryData['phone'] = $("#phone").val();
        table.reload(AmountRecord.tableId, {where: queryData, page:{curr: 1}});
    };


    /**
     * 导出excel按钮
     */
    AmountRecord.exportExcel = function () {
        var checkRows = table.checkStatus(AmountRecord.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + AmountRecord.tableId,
        url: Feng.ctxPath + '/amountRecord/list',
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        limit:15,
        limits: [15,30,50,100],
        cols: AmountRecord.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        AmountRecord.search();
    });
    // 导出excel
    $('#btnExp').click(function () {
    	AmountRecord.exportExcel();
    });
    // 工具条点击事件
    table.on('tool(' + AmountRecord.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        console.log(data);
        console.log(layEvent);
    });
});
